/*
 * @LastEditTime: 2023-02-28 14:36:34
 */
import { router } from "../index";
import { Collection } from "../../Models/Collection.schema";
import { CollectionController } from "../../Controller/Collection.controller";
import { createCollectionDTO, updateCollectionDTO } from "../../DTO/Collection.dto";

const CollectionModel = new CollectionController(Collection);

//获取收藏夹
router.get("/collection", async (ctx, next) => {
  if (ctx.request.query.username) {
    const res = (await CollectionModel.findByUsername(
      ctx.request.query.username.toString()
    )) as { code: number; message: string };
    ctx.body = res;
  }
});

// 创建收藏夹
router.post("/collection", async (ctx, next) => {
  console.log(ctx.request.body);
  ctx.body = await CollectionModel.createItem(ctx.request.body as createCollectionDTO);
});
// 更新收藏夹
router.patch("/collection", async (ctx, next) => {
  if (ctx.request.query.username)
    ctx.body = await CollectionModel.updateById(ctx.params.id, ctx.request.body as updateCollectionDTO);
});